CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12)
PROJECT(cinatra)

OPTION(ENABLE_OPENSSL "Enable use of OpenSSL for https" ON)
OPTION(ENABLE_STATIC_BOOST "Enable use static Boost libs" OFF)

SET(CMAKE_VERBOSE_MAKEFILE ON)

IF (ENABLE_STATIC_BOOST)
	set(Boost_USE_STATIC_LIBS        ON)   # only find static libs
	set(Boost_USE_MULTITHREADED      ON)
	set(Boost_USE_STATIC_RUNTIME    OFF)
ENDIF()

FIND_PACKAGE(Boost 1.55 COMPONENTS coroutine context system thread chrono date_time regex filesystem REQUIRED)

IF(Boost_FOUND)
	INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
	SET(EXTRA_LIBS ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
ENDIF()

FIND_PACKAGE (Threads)
INCLUDE_DIRECTORIES(include)

IF (ENABLE_OPENSSL)
	FIND_PACKAGE(OpenSSL)
	INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR})
	SET(EXTRA_LIBS ${EXTRA_LIBS} ${OPENSSL_LIBRARIES})
	MESSAGE(STATUS "Using OpenSSL ${OPENSSL_VERSION}")
ENDIF()

IF (NOT MSVC)
	ADD_COMPILE_OPTIONS("-std=c++11")
	ADD_COMPILE_OPTIONS("-Wall")
	ADD_COMPILE_OPTIONS("-Wextra")
ENDIF()

IF (WIN32)
	ADD_COMPILE_OPTIONS("-D_WIN32_WINNT=0x0501")
	ADD_COMPILE_OPTIONS("-D_CRT_SECURE_NO_WARNINGS")
	SET(EXTRA_LIBS ${EXTRA_LIBS} ws2_32 mswsock)
ENDIF()

IF (UNIX)
    SET(EXTRA_LIBS ${EXTRA_LIBS} pthread)
ENDIF()

SUBDIRS(examples data_grid)

ADD_CUSTOM_TARGET(debug
	COMMAND ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug ${CMAKE_SOURCE_DIR}
	COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target all
	COMMENT "Switch CMAKE_BUILD_TYPE to Debug"

)
ADD_CUSTOM_TARGET(release
	COMMAND ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Release ${CMAKE_SOURCE_DIR}
	COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target all
	COMMENT "Switch CMAKE_BUILD_TYPE to Release"
)
